package com.iwhalecloud.citybrain.flow.platform.manager.application.service.impl.object;

import com.fasterxml.jackson.databind.JsonNode;
import com.iwhalecloud.citybrain.flow.platform.manager.application.common.context.FlowElementProcessContext;
import com.iwhalecloud.citybrain.flow.platform.manager.application.service.CustomPropertiesProcessor;
import com.iwhalecloud.citybrain.flow.platform.manager.common.ConstanceVariable;
import org.springframework.stereotype.Component;

/**
 * @author lich
 * @date 2021/11/15
 */
@Component
public class SaveNodeObjectMetaProcessor extends SaveObjectMetaAbstractProcessor implements CustomPropertiesProcessor {

    @Override
    public boolean support(JsonNode elementNode) {
        JsonNode properties = elementNode.get("properties");
        if (nonNull(properties)) {
            return nonNull(properties.get(ConstanceVariable.OBJECT_META));
        }
        return false;
    }

    @Override
    public void process(FlowElementProcessContext context) {
        JsonNode modelJson = context.getElementNode();
        JsonNode propertiesNode = context.getModelNode().get("properties");
        String flowCode = propertiesNode.get(ConstanceVariable.PROCESS_ID).asText();
        saveObjectMeta(modelJson, flowCode, context.getDeployId());
    }
}
